package redPacket;

import java.util.ArrayList;

/**
 * @description: ToDo
 * @author: marin
 * @time: 2020/7/3 9:17
 */
public class CommonPacket implements OpenMode {

    @Override
    public ArrayList<Integer> divide(int total, int count) {
        ArrayList<Integer> list = new ArrayList<Integer>();
        int num = total/count;
       /* if((total%count) == 0){
            for(int i =0;i<count;i++){
                list.add(num);
            }
        }else {
            for (int i=0;i<count-1;i++){
                list.add(num);
            }
            list.add(count-1,total-(num*(count-1)));
        }*/

        //优化，通过利用总金额扣除已分配金额
        for(int i =0;i<count;i++){
            list.add(num);
            total-=num;
        }
        list.add(total);
        return list;
    }
}
